// *** LICENSE HEADER ***
// Filename: ./particleemitter.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef NODEWARS_PARTICLE_EMMITER_H
#define NODEWARS_PARTICLE_EMMITER_H

#include <GL/gl.h>
#include <ctime>
#include <cstdlib>
#include "particle.h"
#include "particlesystem.h"
#include "affector.h"
#include "definitions.h"

class particle;
class particleSystem;

//Class holding particle emitting data
class particleEmitter {
    public:
        particleEmitter(float newX, float newY, float newZ, GLuint newTex,
                        int t = _PET_FIRE,
                        float otherX = 0.0f, float otherY = 0.0f, float otherZ = 0.0f,
                        int newLifetime = 5000, int newEmitEnd = 2500,
                        int newParticleLifetimeCenter = 1000,
                        int newParticleLifetimeVariance = 500,
                        int newParticleFadeTime = 1000,
                        int newParticlesPerSecond = 50,
                        float newParticleSize = 0.1f,
                        float newParticleSpeedX = 0.0f,
                        float newParticleSpeedXVariance = 0.1f,
                        float newParticleSpeedY = 0.0f,
                        float newParticleSpeedYVariance = 0.1f,
                        float newParticleSpeedZ = 10.0f,
                        float newParticleSpeedZVariance = 0.5f,
                        float newParticleColorRed = 1.0f,
                        float newParticleColorGreen = 1.0f,
                        float newParticleColorBlue = 1.0f,
                        float newParticleFadeColorRed = 0.0f,
                        float newParticleFadeColorGreen = 0.0f,
                        float newParticleFadeColorBlue = 0.0f);
        ~particleEmitter();

        //Sets the parent pointer and id of this emitter
        void SetParentData(particleSystem* newParent, int newHandle);

        //Updates this emitter
        void Update(int dt);
        //Draws the particles in this emitter
        void Draw();
    private:
        //Returns random float number between minVal and maxVal
        float RandomFloat(float minVal, float maxVal);

        //linked-list of the particles belonging to this emitter
        particle* particles;
        //TextureID used by particles of this emitter
        GLuint texture;

        //Time elapsed after the last generated particle
        int freeTime;

        //Position of the emitter
        float x, y, z;
        //Timing data of the emitter
        int age, lifetime, emitEnd;
        int particlesPerSecond;

        //Particle generation data
        int particleLifetimeCenter, particleLifetimeVariance;
        int particleFadeTime;
        float particleSize;
        float particleSpeedX, particleSpeedXVariance;
        float particleSpeedY, particleSpeedYVariance;
        float particleSpeedZ, particleSpeedZVariance;
        float particleColorRed, particleColorGreen, particleColorBlue;
        float particleFadeColorRed, particleFadeColorGreen, particleFadeColorBlue;

        //Parent data
        particleSystem* parent;
        int myHandle;

        //Affector of the particles in this emitter
        affector* theAff;
};

#endif
